package com.hp.team.bookstore.model.order;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "PURCHASE_ORDER")
public class PurchaseOrder extends Order {

	@OneToMany(mappedBy = "purchaseOrder", cascade = CascadeType.ALL)
	private Collection<Comment> comments = new HashSet<Comment>();

	@OneToMany(mappedBy = "purchaseOrder", cascade = CascadeType.ALL)
	private Collection<PORequirement> poRequirements = new HashSet<PORequirement>();

	@Enumerated(EnumType.STRING)
	@Column(name = "STATUS")
	private POStatus status;

	@OneToMany(mappedBy = "order", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	private Set<PurchaseOrderItem> orderItems = new HashSet<PurchaseOrderItem>();

	public Collection<Comment> getComments() {
		return comments;
	}

	public void setComments(Collection<Comment> comments) {
		this.comments = comments;
	}

	public Collection<PORequirement> getPoRequirements() {
		return poRequirements;
	}

	public void setPoRequirements(Collection<PORequirement> poRequirements) {
		this.poRequirements = poRequirements;
	}

	public POStatus getStatus() {
		return status;
	}

	public void setStatus(POStatus status) {
		this.status = status;
	}

	public Set<PurchaseOrderItem> getOrderItems() {
		return orderItems;
	}

	public void setOrderItems(Set<PurchaseOrderItem> orderItems) {
		this.orderItems = orderItems;
	}

	public void addOrderItem(PurchaseOrderItem orderItem) {
		if (orderItems == null) {
			orderItems = new HashSet<PurchaseOrderItem>();
		}

		for (PurchaseOrderItem item : orderItems) {
			System.out.println("Equality: " + orderItem.equals(item));
		}

		orderItems.add(orderItem);
	}

}
